package industry_2024.industry_05.extract

import org.apache.spark.sql.SparkSession

object table_preparation {
  def main(args: Array[String]): Unit = {
    val spark=SparkSession.builder()
      .master("local[*]")
      .appName("准备表格")
      .config("hive.exec.dynamic.partition.mode","nonstrict")
      .enableHiveSupport()
      .getOrCreate()


    spark.sql("use ods05")

    //  changerecord
    spark.sql("drop table if exists changerecord")
    spark.sql(
      """
        |create table if not exists changerecord(
        |ChangeID int,
        |ChangeMachineID int,
        |ChangeMachineRecordID int,
        |ChangeRecordState string,
        |ChangeStartTime timestamp,
        |ChangeEndTime timestamp,
        |ChangeRecordData string,
        |ChangeHandleState int
        |)
        |partitioned by(etldate string)
        |""".stripMargin)


    //  basemachine
    spark.sql("drop table if  exists basemachine")
    spark.sql(
      """
        |create table if not exists basemachine(
        |BaseMachineID int,
        |MachineFactory int,
        |MachineNo string,
        |MachineName string,
        |MachineIP string,
        |MachinePort int,
        |MachineAddDate timestamp,
        |MachineRemarks string,
        |MachineAddEmpID int,
        |MachineResponsEmpID int,
        |MachineLedgerXml string,
        |ISWS int
        |)
        |partitioned by(etldate string)
        |""".stripMargin)

    //  producerecord
    spark.sql("drop table if exists producerecord")
    spark.sql(
      """
        |create table if not exists producerecord(
        |ProduceRecordID int,
        |ProduceMachineID int,
        |ProduceCodeNumber string,
        |ProduceStartWaitTime timestamp,
        |ProduceCodeStartTime timestamp,
        |ProduceCodeEndTime timestamp,
        |ProduceCodeCycleTime int,
        |ProduceEndTime timestamp,
        |ProducePrgCode string,
        |ProduceTotalOut int,
        |ProduceInspect int
        |)
        |partitioned by(etldate string)
        |""".stripMargin)

    //  machinedata
    spark.sql("drop table if exists machinedata")
    spark.sql(
      """
        |create table if not  exists  machinedata(
        |MachineRecordID int,
        |MachineID int,
        |MachineRecordState string,
        |MachineRecordData string,
        |MachineRecordDate timestamp
        |)
        |partitioned by(etldate string)
        |""".stripMargin)





    spark.close()
  }

}
